package com.example.springbootrabbitmqproducer.sender;

import java.util.Date;

import com.example.springbootrabbitmqconsumer.config.RabbitConfig;
import com.example.springbootrabbitmqconsumer.entity.Merchant;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Service
public class RabbitSender {


    @Autowired
    private AmqpTemplate rabbitTemplate;

    public void send(){

        String context = "hello " + new Date();
        Merchant merchant = new Merchant(context);
        //直连类型交换机
        this.rabbitTemplate.convertAndSend(RabbitConfig.directExchange, RabbitConfig.DIRECT_EXCHANGE_ROUTING_KEY,merchant);
        //topic类型交换机
        this.rabbitTemplate.convertAndSend(RabbitConfig.topicExchange, RabbitConfig.TOPIC_EXCHANGE_ROUTING_KEY,"a topic msg: this.rabbitmq.msg");
        //队列类型交换机
        this.rabbitTemplate.convertAndSend(RabbitConfig.fanoutExchange, "","a fanout msg:this is fanoutExchange msg");

    }
}
